package com.maidada.mddaichat.util;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author wulinxuan
 * @date 2025-04-17 12:27
 */
public class RedisUtils {

    private static final StringRedisTemplate TEMPLATE;

    static {
        TEMPLATE = SpringUtil.getBean(StringRedisTemplate.class);
    }

    public static void set(String key, String value, long expire, TimeUnit timeUnit) {
        TEMPLATE.opsForValue().set(key, value, expire, timeUnit);
    }

    public static void setWithMinutes(String key, String value, long expire) {
        set(key, value, expire, TimeUnit.MINUTES);
    }

    public static void setWithHours(String key, String value, long expire) {
        set(key, value, expire, TimeUnit.HOURS);
    }

    public static void setWithDays(String key, String value, long expire) {
        set(key, value, expire, TimeUnit.DAYS);
    }

    public static String get(String key) {
        return TEMPLATE.opsForValue().get(key);
    }
}
